package gomz.pres.admin;

import gomz.pres.CheckBoxList;
import gomz.pres.GUIMain;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;

/**
 * Diese Klasse erstellt das GUI des Exports in der Verwaltung
 * 
 * @author Dilji
 */

public class GUIAExport {

	// all the variables for main panels
	private JPanel plExport;
	private JPanel plExportNord;
	private JScrollPane spExport;

	// all the variables
	private JLabel lbJExportTitle;
	private JLabel lbJcat;
	private JScrollPane spJcat;
	private CheckBoxList liJcat;
	private JLabel lbJque;
	private JScrollPane spJque;
	private CheckBoxList liJque;
	private JLabel lbJartTyp;
	private JRadioButton rbJone;
	private JRadioButton rbJall;
	private JLabel lbJdataTyp;
	private JRadioButton rbJcsv;
	private JRadioButton rbJword;
	private JRadioButton rbJxml;
	private JButton btJexport;
	private JButton btJcan;
	private ButtonGroup artTypGroup;
	private ButtonGroup dataTypGroup;

	/**
	 * Erstellt das GUI fuer den Export
	 * @param categorieList fuellt die Kategorieliste
	 * @param questionList fuellt die Fragenliste
	 * @return gibt das GUI zurueck
	 */
	public JScrollPane getTab(String[] categorieList, String[] questionList) {

		// initialize the panels, add to scrollpane and set position
		this.plExport = new JPanel();
		this.plExportNord = new JPanel();
		this.spExport = new JScrollPane(plExportNord);
		this.plExportNord.setLayout(new BorderLayout());
		this.plExportNord.setBorder(new EmptyBorder((2 * GUIMain.getAbstand()), 0, GUIMain.getAbstand(), 0));
		this.plExportNord.add(plExport, BorderLayout.NORTH);

		// set background of main panels
		this.plExport.setBackground(Color.WHITE);
		this.plExportNord.setBackground(Color.WHITE);

		// initialize the components
		this.lbJExportTitle = new JLabel("Export");
		this.lbJcat = new JLabel("Kategorie ausw\u00e4hlen:");
		this.liJcat = new CheckBoxList(categorieList);
		this.spJcat = new JScrollPane(liJcat);
		this.lbJque = new JLabel("Frage ausw\u00e4hlen:");
		this.liJque = new CheckBoxList(questionList);
		this.spJque = new JScrollPane(liJque);
		this.lbJartTyp = new JLabel("Art ausw\u00e4hlen:");
		this.artTypGroup = new ButtonGroup();
		this.rbJone = new JRadioButton("Alle Fragen in ein Dokument");
		this.rbJall = new JRadioButton("Jede Frage in ein Dokument");
		this.lbJdataTyp = new JLabel("Dateityp ausw\u00e4hlen:");
		this.dataTypGroup = new ButtonGroup();
		this.rbJword = new JRadioButton("Word-Datei");
		this.rbJcsv = new JRadioButton("CSV-Datei");
		this.btJexport = new JButton("Exportieren");
		this.btJcan = new JButton("Zur\u00fccksetzen");

		// set default select
		this.rbJone.setSelected(true);
		this.rbJword.setSelected(true);

		// Group the radio buttons
		this.artTypGroup.add(this.rbJone);
		this.artTypGroup.add(this.rbJall);
		this.dataTypGroup.add(this.rbJcsv);
		this.dataTypGroup.add(this.rbJword);

		// FontSize for title
		this.lbJExportTitle.setFont(GUIMain.getTitlefont());
		this.lbJExportTitle.setForeground(GUIMain.getTitleblue());

		// size of scrollpane for list
		this.spJcat.setPreferredSize(new Dimension(295, 200));
		this.spJcat.setMaximumSize(new Dimension(295, 200));
		this.spJque.setPreferredSize(new Dimension(295, 200));
		this.spJque.setMaximumSize(new Dimension(295, 200));

		// size of buttons
		this.btJexport.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btJexport.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btJcan.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btJcan.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));

		// background of RadioButtons
		this.rbJall.setBackground(Color.WHITE);
		this.rbJone.setBackground(Color.WHITE);
		this.rbJcsv.setBackground(Color.WHITE);
		this.rbJword.setBackground(Color.WHITE);

		// BOX artTyp
		Box artBox = Box.createVerticalBox();
		artBox.add(this.lbJartTyp);
		artBox.add(Box.createVerticalStrut(GUIMain.getAbstand() / 2));
		artBox.add(this.rbJone);
		artBox.add(Box.createVerticalStrut(GUIMain.getAbstand() / 5));
		artBox.add(this.rbJall);

		// BOX dataTyp
		Box dataBox = Box.createVerticalBox();
		dataBox.add(this.lbJdataTyp);
		dataBox.add(Box.createVerticalStrut(GUIMain.getAbstand() / 2));
		dataBox.add(this.rbJword);
		dataBox.add(Box.createVerticalStrut(GUIMain.getAbstand() / 5));
		dataBox.add(this.rbJcsv);

		// BOX dataTyp
		Box btJBox = Box.createHorizontalBox();
		btJBox.add(this.btJexport);
		btJBox.add(Box.createHorizontalStrut(GUIMain.getAbstand()));
		btJBox.add(this.btJcan);

		// scroll speed
		this.spExport.getVerticalScrollBar().setUnitIncrement(GUIMain.getScrollspeed());
		this.spJcat.getVerticalScrollBar().setUnitIncrement(GUIMain.getScrollspeed());
		this.spJque.getVerticalScrollBar().setUnitIncrement(GUIMain.getScrollspeed());

		// border color
		this.spJcat.setBorder(GUIMain.getBorderColor());
		this.spJque.setBorder(GUIMain.getBorderColor());

		// position of components
		this.plExport.setLayout(new GridBagLayout());
		GridBagConstraints cj = new GridBagConstraints();
		cj.fill = GridBagConstraints.HORIZONTAL; // in x-Achse ausfuellen
		cj.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cj.anchor = GridBagConstraints.NORTHWEST; // Ausrichtung oben

		cj.gridx = 0; // Spalte 1
		cj.gridy = 0; // Zeile 1
		cj.gridwidth = 2;
		plExport.add(lbJExportTitle, cj); // label Title

		cj.gridx = 1; // Spalte 2
		cj.gridy = 0; // Zeile 1
		cj.gridwidth = 1;
		// plExport.add(, cj); // Com

		cj.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, (3 * GUIMain.getAbstand()));
		cj.gridx = 0; // Spalte 1
		cj.gridy = 1; // Zeile 2
		plExport.add(lbJcat, cj); // Label Kategorie

		cj.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cj.gridx = 1; // Spalte 2
		cj.gridy = 1; // Zeile 2
		plExport.add(lbJque, cj); // Label Fragen

		cj.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cj.gridx = 0; // Spalte 1
		cj.gridy = 2; // Zeile 3
		plExport.add(spJcat, cj); // Liste Kategorie

		cj.gridx = 1; // Spalte 2
		cj.gridy = 2; // Zeile 3
		plExport.add(spJque, cj); // Liste Fragen

		cj.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cj.gridx = 0; // Spalte 1
		cj.gridy = 3; // Zeile 4
		plExport.add(dataBox, cj); // Auswahl Datenformat

		cj.gridx = 1; // Spalte 2
		cj.gridy = 3; // Zeile 4
		plExport.add(artBox, cj); // Auswahl Dokument

		cj.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cj.gridx = 0; // Spalte 1
		cj.gridy = 4; // Zeile 5
		plExport.add(btJBox, cj); // Buttons

		cj.gridx = 1; // Spalte 2
		cj.gridy = 4; // Zeile 5
		// plExport.add(, cj); // Com

		return (spExport);
	}

	// ********************************************************************************
	// Getters und Setters
	// ********************************************************************************

	public CheckBoxList getLiJcat() {
		return liJcat;
	}

	public void setLiJcat(CheckBoxList liJcat) {
		this.liJcat = liJcat;
	}

	public CheckBoxList getLiJque() {
		return liJque;
	}

	public void setLiJque(CheckBoxList liJque) {
		this.liJque = liJque;
	}

	public JButton getBtJexport() {
		return btJexport;
	}

	public void setBtJexport(JButton btJexport) {
		this.btJexport = btJexport;
	}

	public JButton getBtJcan() {
		return btJcan;
	}

	public void setBtJcan(JButton btJcan) {
		this.btJcan = btJcan;
	}

	public ButtonGroup getArtTypGroup() {
		return artTypGroup;
	}

	public void setArtTypGroup(ButtonGroup artTypGroup) {
		this.artTypGroup = artTypGroup;
	}

	public ButtonGroup getDataTypGroup() {
		return dataTypGroup;
	}

	public void setDataTypGroup(ButtonGroup dataTypGroup) {
		this.dataTypGroup = dataTypGroup;
	}

	public JRadioButton getRbJone() {
		return rbJone;
	}

	public void setRbJone(JRadioButton rbJone) {
		this.rbJone = rbJone;
	}

	public JRadioButton getRbJall() {
		return rbJall;
	}

	public void setRbJall(JRadioButton rbJall) {
		this.rbJall = rbJall;
	}

	public JRadioButton getRbJcsv() {
		return rbJcsv;
	}

	public void setRbJcsv(JRadioButton rbJcsv) {
		this.rbJcsv = rbJcsv;
	}

	public JRadioButton getRbJword() {
		return rbJword;
	}

	public void setRbJword(JRadioButton rbJword) {
		this.rbJword = rbJword;
	}

	public JRadioButton getRbJxml() {
		return rbJxml;
	}

	public void setRbJxml(JRadioButton rbJxml) {
		this.rbJxml = rbJxml;
	}

}
